<!DOCTYPE html>
<html lang="en" class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>行业动态配置</title>
    <header th:replace="header::html"></header>
</head>

<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a><cite>首页</cite></a>
            <a><cite>门户管理</cite></a>
            <a><cite>行业动态配置</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>

<div class="layui-fluid">
    <div class="layui-row  layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form  layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="ntitle" placeholder="请输入标题关键字" autocomplete="off"
                                   class="layui-input">
                        </div>

                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="test20" placeholder="请选择动态的获取日期"
                                       name="getInfoDate">
                            </div>
                        </div>
                        <div class="layui-input-inline">
                            <select name="ncontent" lay-filter="ncontent">
                                <option value="">请选择动态类型</option>
                                <option value="数码通讯">数码通讯</option>
                                <option value="生活服务">生活服务</option>
                                <option value="智能硬件">智能硬件</option>
                                <option value="软件科学">软件科学</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="search"><i
                                    class="layui-icon">&#xe615;</i></button>
                        </div>

                        <div class="layui-input-inline">
                            <select name="typetype" lay-filter="typetype" id="typetype">
                                <option value="">请选择需要获取的动态类型</option>
                                <option value="数码通讯行业">数码通讯行业</option>
                                <option value="生活服务行业">生活服务行业</option>
                                <option value="智能硬件行业">智能硬件行业</option>
                                <option value="软件科学行业">软件科学行业</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button type="button" class="layui-btn layui-btn-fluid" onclick="getLatest()">--获取今日行业最新动态--
                            </button>
                        </div>
                    </form>
                </div>


                <div class="layui-card-body ">
                    <table class="layui-hide" id="industryDynamics" lay-filter="industryDynamics"></table>
                </div>

                <div class="layui-card-body ">
                    <script type="text/html" id="barDemo">
                        <a class="layui-btn layui-btn-xs" lay-event="open"
                        >发布</a>
                        <a class="layui-btn layui-btn-xs" lay-event="close"
                        >下架</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="edit"
                        >编辑</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"
                        >删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>

	layui.use('laydate', function () {
		var laydate = layui.laydate;
		//选中后的回调
		laydate.render({
			elem: '#test20'
			, done: function (value, date) {
				//	layer.alert('你选择的日期是：' + value + '<br>获得的对象是' + JSON.stringify(date));
			}
		});
	});


	layui.use('table', function () {
		var table = layui.table,
			form = layui.form;
		table.render({
			elem: '#industryDynamics'
			, url: '/api-back/industryDynamics/list' //数据接口
			, page: true //开启分页
			, cellMinWidth: 80 //全局定义常规单元格的最小宽度
			, response: {
				dataName: 'datas' //规定数据列表的字段名称，默认：data
			}
			, cols: [
				[ //表头
					{type: 'checkbox', fixed: 'left'}
					, {title: '序号', type: 'numbers', width: '5%'}
					, {field: 'nid', title: 'ID', align: 'center', sort: true, width: "5%", style: 'display:none;'}
					, {field: 'ncontent', title: '类型', align: 'center'}
					, {field: 'ntitle', title: '动态', sort: true, width: "25%"}
					, {field: 'nurl', title: 'URL', align: 'center'}
					, {field: 'ntime', title: '获取时间', align: 'center', width: "8%"}
					, {field: 'tips1', title: '发布者', align: 'center', width: "5%"}
					, {field: 'tips2', title: '发布时间', align: 'center', width: "8%"}
					, {title: '操作', toolbar: '#barDemo', align: 'center', width: "20%"}
				]
			],
			done: function () {
				//checkPermission();
				$('table.layui-table thead tr th:eq(2)').addClass('layui-hide');//隐藏第一列的表头
			}
		});

		//监听工具条
		table.on('tool(industryDynamics)', function (obj) {
			var data = obj.data;//获取点击行数据
			if (obj.event === 'del') {
				layer.confirm('确认删除该条资讯吗?', function (index) {
					$.ajax({
						url: "/api-back/industryDynamics/delete",
						type: "GET",
						data: {nid: data.nid},
						dataType: 'json',
						success: function (result) {
							layer.alert("删除成功", {icon: 1}, function (index1) {
								layer.close(index1);
								table.reload('industryDynamics');
								$('table.layui-table thead tr th:eq(2)').addClass('layui-hide');//隐藏第一列的表头
							});
						},
						error: function () {
							layer.open({
								type: 2,
								content: "/404.html",
								area: ['60%', '60%'],
								title: '权限不足'
							});
						}
					});
				});
			} else if (obj.event === 'open') {
				layer.confirm('确认发布该条资讯到门户吗?', function (index) {
					if (data.tips1 == null || data.tips1 == '') {
						$.ajax({
							url: "/api-back/industryDynamics/open",
							type: "GET",
							data: {nid: data.nid},
							dataType: 'json',
							success: function (result) {
								layer.alert("发布成功", {icon: 1}, function (index1) {
									layer.close(index1);
									//xadmin.father_reload();
									table.reload('industryDynamics');
									$('table.layui-table thead tr th:eq(2)').addClass('layui-hide');//隐藏第一列的表头
								});
							},
							error: function () {
								layer.open({
									type: 2,
									content: "/404.html",
									area: ['60%', '60%'],
									title: '权限不足'
								});
							}
						});
					} else {
						layer.alert("已发布的需求无法重复发布，请确认！", {icon: 2})
					}

				});
			} else if (obj.event === 'close') {
				layer.confirm('确认下架该条资讯吗?', function (index) {
						if (data.tips1 !== null && data.tips1 !== '') {
							$.ajax({
								url: "/api-back/industryDynamics/close",
								type: "GET",
								data: {nid: data.nid},
								dataType: 'json',
								success: function (result) {
									layer.alert("下架成功", {icon: 1}, function (index1) {
										layer.close(index1);
										//xadmin.father_reload();
										table.reload('industryDynamics');
										$('table.layui-table thead tr th:eq(2)').addClass('layui-hide');//隐藏第一列的表头
									});
								},
								error: function () {
									layer.open({
										type: 2,
										content: "/404.html",
										area: ['60%', '60%'],
										title: '权限不足'
									});
								}
							});
						} else {
							layer.alert("已发布的需求才可以下架，请确认！", {icon: 2})
						}
					}
				);
			} else if (obj.event === 'edit') {
				layer.prompt({title: '请输入新的动态标题，并确认', formType: 2}, function (pass, index) {
					if (pass.trim().length >= 20 || pass.trim().length < 5) {
						layer.msg("对不起，字数请限制在5到20位，请检查！");
					} else {
						$.ajax({
							url: "/api-back/industryDynamics/edit",
							type: "GET",
							data: {
								nid: data.nid,
								ntitle: pass
							},
							dataType: 'json',
							success: function (result) {
								layer.alert("修改成功", {icon: 1}, function (index1) {
									layer.close(index1);
								});
							},
							error: function () {
								layer.open({
									type: 2,
									content: "/404.html",
									area: ['60%', '60%'],
									title: '权限不足'
								});
							}
						});
						layer.close(index);
						table.reload('industryDynamics');
						$('table.layui-table thead tr th:eq(2)').addClass('layui-hide');//隐藏第一列的表头
					}
				});
			}
		});

		//搜索
		form.on('submit(search)', function (data) {
			var field = data.field;
			table.render({
				elem: '#industryDynamics'
				, url: '/api-back/industryDynamics/findIndustryByFuzzy' //数据接口
				, page: true //开启分页
				, where: {
					"ntitle": field.ntitle,
					"getDate": field.getInfoDate,
					"ncontent": field.ncontent
				}
				, response: {
					dataName: 'datas' //规定数据列表的字段名称，默认：data
				}
				, cols: [
					[ //表头
						{type: 'checkbox', fixed: 'left'}
						, {title: '序号', type: 'numbers', width: '5%'}
						, {field: 'nid', title: 'ID', align: 'center', sort: true, width: "5%", style: 'display:none;'}
						, {field: 'ncontent', title: '类型', align: 'center'}
						, {field: 'ntitle', title: '动态', sort: true, width: "25%"}
						, {field: 'nurl', title: 'URL', align: 'center'}
						, {field: 'ntime', title: '获取时间', align: 'center', width: "8%"}
						, {field: 'tips1', title: '发布者', align: 'center', width: "5%"}
						, {field: 'tips2', title: '发布时间', align: 'center', width: "8%"}
						, {title: '操作', toolbar: '#barDemo', align: 'center', width: "20%"}
					]
				],
				done: function () {
					//checkPermission();
					$('table.layui-table thead tr th:eq(2)').addClass('layui-hide');//隐藏第一列的表头
				}
				,
				error: function () {
					layer.open({
						type: 2,
						content: "/404.html",
						area: ['60%', '60%'],
						title: '权限不足'
					});
				}
			});
			return false;
		});

	});

	function getLatest() {
		layer.confirm('确认获取该行业的今日动态吗?', function (index) {
			var type = $('#typetype option:selected');
			if (type.val() !== "" && type.val() !== null) {
				$.ajax({
					url: "/api-back/worm/spiterToIndustry",
					type: "GET",
					data: {industry: type.val()},
					success: function (result) {
						layer.alert("获取成功", {icon: 1}, function (index1) {
							layer.close(index1);
							xadmin.father_reload();
						});
					}, error: function () {
						layer.open({
							type: 2,
							content: "/404.html",
							area: ['60%', '60%'],
							title: '权限不足'
						});
					}
				});
			} else {
				layer.alert("请选择正确的行业动态类型，请确认！", {icon: 2})
			}
		});
	}
</script>
</html>